<?php 
// Do the real action (Add, Delete and Modify)
require "hrfuns.php";
Valid_Client();

if (isset($_POST["Action"])) {
    $iSQL = GetSQL(); 
    switch ($_POST["Action"]) {
    case "Add":
        $date = FormatDate($_POST["Date"]);
        if (! $date) {
            die("休假时间输入错误: " . $_POST["Date"]);
        }
        $sqlstr = "insert into va_t values(" 
                . " '" . $_POST["EmId"] . "'"
                . ", " . $_POST["VaType"]
                . ", '" . $date . "'"
                . ", " . $_POST["Length"] . ")";
        break;
    
    case "Delete":
        $sqlstr = "delete from va_t"
                . " where em_id = '". $_POST["EmId"] . "'"
                . " and va_type_id = " . $_POST["VaType"]
                . " and va_date = '" . $_POST["Date"] . "'"; 
        break;
    case "Modify":
        $sqlstr = "update va_t"
                . " set va_length=" . $_POST["Length"]
                . " where em_id = '". $_POST["EmId"] . "'"
                . " and va_type_id=" . $_POST["VaType"]
                . " and va_date='" . $_POST["Date"] ."'";
        break;
    default:
        exit;
    }

    if (isset($sqlstr) && strlen($sqlstr) > 0) {
        $result = $iSQL->query($sqlstr);
        if (! $result) 
            echo $_POST["Action"] . "Failed: $sqlstr";
    }
    $iSQL->close();
}
?>
